library(googlesheets)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
df <- gs_title("TB systematic review plan")
## Sheet successfully identified: "TB systematic review plan"
StudyArea <- df %>% gs_read(ws = 'Study area table')
## Accessing worksheet titled 'Study area table'.
## Parsed with column specification:
## cols(
## StudyID = col_integer(),
## SubID = col_integer(),
## `Third-order Administrative division` = col_character(),
## `Second-order administrative division` = col_character(),
## `First-Order Administrative division` = col_character(),
## Country = col_character(),
## Latitude = col_character(),
## Longitude = col_character(),
## `Elevation (m)` = col_character()
## )
CaseCount <- df %>% gs_read(ws = 'Time series table')
## Accessing worksheet titled 'Time series table'.
## Parsed with column specification:
## cols(
## StudyID = col_integer(),
## SubID = col_integer(),
## Date = col_character(),
## CaseCount = col_number()
## )
CaseCount$Date <- as.Date(CaseCount$Date)
# combine study ID andn subID
CaseCount$ID <- paste(CaseCount$StudyID, CaseCount$SubID, sep = "_")
unique.place <- unique(StudyArea[,1:6])
Beijing
library(ggplot2)
# Beijing
cities <- CaseCount[CaseCount$ID %in% c("932_1","1514_1"),]
ggplot(cities, aes(x = Date, y = CaseCount, col = ID)) + geom_line() + theme_bw() + ggtitle("Beijing")

Hongkong
cities <- CaseCount[CaseCount$ID %in% c("932_2","1077_1"),]
ggplot(cities, aes(x = Date, y = CaseCount, col = ID)) + geom_line() + theme_bw() + ggtitle("Hong Kong")

Wuhan
cities <- CaseCount[CaseCount$ID %in% c("1431_1","1431_2","398_1"),]
# sum up smear+ and smear- cases in 1431
cities <- aggregate(CaseCount ~ StudyID + Date, cities, sum)
ggplot(cities, aes(x = Date, y = CaseCount, col = as.factor(StudyID))) + geom_line() + theme_bw() + ggtitle("Wuhan")

Jiangxi
cities <- CaseCount[CaseCount$ID %in% c("165_1","1419_1"),]
ggplot(cities, aes(x = Date, y = CaseCount, col = ID)) + geom_line() + theme_bw() + ggtitle("Jiangxi")

China
cities <- CaseCount[CaseCount$ID %in% paste(c(196, 291, 428, 498, 730, 936, 1329, 1451, 1475, 1503),"_1", sep = ""),]
China <- ggplot(cities, aes(x = Date, y = CaseCount, col = ID)) + geom_line() + theme_bw() + ggtitle("China")
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
ggplotly(China)
Iran
cities <- CaseCount[CaseCount$ID %in% paste(c(36, 42, 523, 1080),"_1", sep = ""),]
ggplot(cities, aes(x = Date, y = CaseCount, col = ID)) + geom_line() + theme_bw() + ggtitle("Iran")

Mongolia
cities <- CaseCount[CaseCount$ID %in% c("243_2", "721_1"),]
cities.plot <- ggplot(cities, aes(x = Date, y = CaseCount, col = ID)) + geom_line() + theme_bw() + ggtitle("Mongolia")
ggplotly(cities.plot)
United States
cities <- CaseCount[CaseCount$ID %in% paste(c(441, 583, 1252),"_1", sep = ""),]
ggplot(cities, aes(x = Date, y = CaseCount, col = ID)) + geom_line() + theme_bw() + ggtitle("United States")
